package cn.com.se.sharepictrue.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.com.se.sharepictrue.R;
import cn.com.se.sharepictrue.adapter.BaseFragmentPagerAdapter;
import cn.com.se.sharepictrue.bean.FragmentPager;
import cn.com.se.sharepictrue.fragment.RankFragment;

/**
 * 点赞榜界面
 * Created by KIDNG on 2015/11/5.
 */
public class RankActivity extends ActionBarActivity {
    @Bind(R.id.tb_concern_title)
    Toolbar mTbConcernTitle;
    @Bind(R.id.tl_rank_tabs)
    TabLayout mTlTabs;
    @Bind(R.id.vp_rank_content)
    ViewPager mVpPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rank);
        ButterKnife.bind(this);
        initToolbar();
        initPager();
    }

    private void initPager() {
        List<FragmentPager> list = new ArrayList<>();
        list.add(new FragmentPager(RankFragment.getNewInstance(RankFragment.TYPE_TODAY_PRAISE),"今天"));
        list.add(new FragmentPager(RankFragment.getNewInstance(RankFragment.TYPE_WEEK_PRAISE),"最近一周"));
        list.add(new FragmentPager(RankFragment.getNewInstance(RankFragment.TYPE_ALL_PRAISE),"全部"));
        mVpPager.setAdapter(new BaseFragmentPagerAdapter(getSupportFragmentManager(),list));
        mTlTabs.setupWithViewPager(mVpPager);
    }

    private void initToolbar() {
        setSupportActionBar(mTbConcernTitle);
        mTbConcernTitle.setTitleTextColor(Color.WHITE);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
